Skip to content

Add Process.TryGetProcessById and silent param on Run/RunAsync#568

Merged
SimonCropp merged 4 commits into
mainfrom
Add-net11-Process.TryGetProcessById-and-silent-param-on-Run/RunAsync
Jul 14, 2026
Merged

Add Process.TryGetProcessById and silent param on Run/RunAsync#568
SimonCropp merged 4 commits into
mainfrom
Add-net11-Process.TryGetProcessById-and-silent-param-on-Run/RunAsync

Conversation

@SimonCropp

@SimonCropp SimonCropp commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

Brings the Process polyfill in line with the .NET 11 BCL surface:

  • Adds silent overloads to Process.Run / Process.RunAsync (suppress child stdout/stderr).
  • Adds Process.TryGetProcessById(int, out Process?).

⚠️ Why this is a breaking change

Run and RunAsync gained a bool silent parameter, and to match the real .NET 11 signatures it was inserted in the middle of the parameter list — not appended at the end:

- Run(string fileName, IList<string>? arguments = null, TimeSpan? timeout = default)
+ Run(string fileName, IList<string>? arguments = null, bool silent = false, TimeSpan? timeout = default)

- RunAsync(string fileName, IList<string>? arguments = null, CancellationToken cancellationToken = default)
+ RunAsync(string fileName, IList<string>? arguments = null, bool silent = false, CancellationToken cancellationToken = default)

Because the new parameter sits in the 3rd positional slot (ahead of timeout / cancellationToken), any caller that passed the third argument positionally no longer compiles:

// Previously valid — now a compile error (CS1503):
Process.Run("dotnet", args, timeout);                 // TimeSpan? → bool
await Process.RunAsync("dotnet", args, cancelToken);  // CancellationToken → bool

Polyfill ships as source, so this is a source/compile-time break that surfaces the moment a consumer updates the package and rebuilds (there's no binary-compat layer to absorb it). All existing Run/RunAsync call sites using a positional 3rd argument must be updated.

Why insert mid-list instead of appending?

The parameter order deliberately mirrors the .NET 11 BCL:

  • Process.Run(string, IList<string>, bool, TimeSpan?)
  • Process.RunAsync(string, IList<string>, bool, CancellationToken)

Appending silent at the end would keep source-compat today but diverge from the BCL, so the same call would break later when a consumer moves to net11 and the polyfill retires in favor of the framework method (ProcessPolyfill.cs is gated #if !NET11_0_OR_GREATER). Taking the one-time break now keeps call sites identical across the polyfill→BCL boundary.

Migration

Use named arguments for the trailing parameter:

- Process.Run("dotnet", args, timeout);
+ Process.Run("dotnet", args, timeout: timeout);

- await Process.RunAsync("dotnet", args, cancelToken);
+ await Process.RunAsync("dotnet", args, cancellationToken: cancelToken);

Or pass silent explicitly if adopting the new behavior.

Non-breaking additions

  • Process.TryGetProcessById(int processId, out Process? process) — purely additive (throws ArgumentOutOfRangeException for processId <= 0, returns false when no such process exists).
  • silent: true on Run/RunAsync redirects and discards stdout/stderr. Note: on pre-net11 the polyfill suppresses by redirecting-and-discarding (stdin stays connected), which differs slightly from net11 binding to the null device.

- Process.TryGetProcessById(int, out Process?)
- add `silent` to the fileName overloads of Process.Run/RunAsync
  (net11 preview6 inserts it after arguments, before timeout/cancellationToken)
@SimonCropp SimonCropp added this to the 11.0.0 milestone Jul 14, 2026
@SimonCropp SimonCropp changed the title Add net11 process.try get process by id and silent param on run/run async Add Process.TryGetProcessById and silent param on Run/RunAsync Jul 14, 2026
@SimonCropp
SimonCropp merged commit 93bd635 into main Jul 14, 2026
6 of 8 checks passed
@SimonCropp
SimonCropp deleted the Add-net11-Process.TryGetProcessById-and-silent-param-on-Run/RunAsync branch July 14, 2026 21:25
This was referenced Jul 14, 2026
This was referenced Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant